from PySide6.QtWidgets import QProgressBar
from PySide6.QtCore import Signal

class TgProgressBar(QProgressBar):
    """进度条组件 - 基于QProgressBar"""
    
    # 组件状态变化信号
    state_changed = Signal(str, object)  # 信号：状态名，新值
    
    def __init__(self, parent=None):
        super().__init__(parent)
        self._component_name = self.__class__.__name__
        self._is_initialized = False
        self._style_applied = False
        
        # 设置默认值
        self.setRange(0, 100)
        self.setValue(0)
        
        # 初始化组件
        self.initialize()
    
    @property
    def component_name(self):
        """获取组件名称"""
        return self._component_name
    
    @property
    def is_initialized(self):
        """检查组件是否已初始化"""
        return self._is_initialized
    
    @property
    def style_applied(self):
        """检查样式是否已应用"""
        return self._style_applied
    
    def emit_state_changed(self, state_name, value):
        """发射状态变化信号"""
        self.state_changed.emit(state_name, value)
    
    def initialize(self):
        """初始化组件"""
        if not self._is_initialized:
            self.setup_ui()
            self.apply_style()
            self._is_initialized = True
    
    def setup_ui(self):
        """设置UI - 子类可重写"""
        pass
    
    def apply_style(self):
        """应用样式 - 子类可重写"""
        self._style_applied = True